package colony;

import java.util.List;

public class DistanceMatrix {

	public static double matrix[][];
	public static double media=0;
	public static double max = 0;
	public static double std[];

	public DistanceMatrix(List<Item> items) {
		super();

		matrix = new double[items.size()][items.size()];
		std = new double[items.size()];

		int count = 0;
		for (int i = 0; i < items.size(); i++) {
			for (int j = i; j < items.size(); j++) {
				double value = items.get(i).distanceEuclidean(items.get(j));
				//System.out.println(value);
				matrix[i][j] = value;
				matrix[j][i] = value;
				
				if(value > max){
					max = value;
				}
				media += value;
				count++;
			}
		}
		media /= count;
		
		//Engine.penalty = max;
		Engine.penalty = media;	
		compute();
		//System.out.println(total);

	}
	
	public void compute(){
		for (int i = 0; i < matrix.length; i++) {
			double aux = 0;
			for (int j = 0; j < matrix[i].length; j++) {
				//aux += Math.pow(matrix[i][j] - media, 2);
				aux += matrix[i][j];
				
			}
			//double div = 1.0/matrix[i].length;
			//std[i] = Math.sqrt(div*aux);
			std[i] = aux/matrix[i].length;
			//System.out.println("std "+i+": "+std[i]);
			}
		//System.out.println("media: "+media);
	}

	public void print() {
		System.out.println("matrix");
		for (int i = 0; i < matrix.length; i++) {
			System.out.println("item: "+i);
			for (int j = 0; j < matrix[i].length; j++) {
				System.out.print(matrix[i][j]+" ");
			}
			System.out.println("\n");
		}
	}

	public double get(int i, int j) {
		return matrix[i][j];
	}

}
